package com.bloody.android;

import java.util.ArrayList;

import com.bloody.android.Characters.Character;
import com.bloody.android.Map.Case;
import com.bloody.android.Map.Map;

import android.os.Bundle;

public class Utility {
	
	private static void caseSave(Bundle save, Map map){
    	Case cases[][] = map.getCases();
		
		for (int i=0; i<map.getRow(); i++){
			for (int j=0; j<map.getColumn(); j++){
				save.putInt("case-" + Integer.toString(i) + 
						"-" + Integer.toString(j) + "-posx", 
						cases[i][j].getPosx());
				save.putInt("case-" + Integer.toString(i) + 
						"-" + Integer.toString(j) + "-posy", 
						cases[i][j].getPosy());
				save.putInt("case-" + Integer.toString(i) + 
						"-" + Integer.toString(j) + "-landscape", 
						cases[i][j].getLandscape());
				save.putBoolean("case-" + Integer.toString(i) + 
						"-" + Integer.toString(j) + "-check", 
						cases[i][j].isCheck());
			}	
		}
    	
    }
    
    public static void mapSaving(Bundle save, Map map){
    	
    	save.putInt("mapRow", map.getRow());
    	save.putInt("mapColumn", map.getColumn());
    	caseSave(save, map);	
    }
    
    public static void characterSaving(Bundle save, ArrayList<Character> characters, String name){
    	for (int i=0; i<characters.size(); i++){
    		String[] tmpName = characters.get(i).getClass().getName().split("\\.");
    		
    		save.putString(name+ "-"+ Integer.toString(i)+ "-type", 
						tmpName[tmpName.length-1]);
    		save.putInt(name+"-"+ Integer.toString(i)+ "-player", 
    				characters.get(i).getPlayer());
    		save.putInt(name+"-"+ Integer.toString(i)+ "-posx", 
    				characters.get(i).getPosx());
    		save.putInt(name+"-"+ Integer.toString(i)+ "-posy", 
    				characters.get(i).getPosy());
    		save.putInt(name+"-"+ Integer.toString(i)+ "-life", 
    				characters.get(i).getLife());
    	}
    	save.putInt(name+"-size", 
				characters.size());
    }

}
